/*
 * MainFrame.java
 *
 * Created on __DATE__, __TIME__
 */

package com.wdzl.frames;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.*;

import com.wdzl.biz.EmpBiz;
import com.wdzl.biz.ManagerBiz;

/**
 *
 * 功能演示  代码讲解  使用方法
 */
public class LoginFrame extends JFrame {

	private final ManagerBiz biz = new ManagerBiz();

	/**
	 * Creates new form LoginFrame
	 */
	public LoginFrame() {
		initComponents();
	}

	/**
	 *
	 */
	private void initComponents() {

		jLabel1 = new JLabel();
		jSeparator1 = new JSeparator();
		jLabel2 = new JLabel();
		jTextField1 = new JTextField();
		jLabel3 = new JLabel();
		jPasswordField1 = new JPasswordField();
		jButton1 = new JButton();
		jButton2 = new JButton();

		setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);

		jLabel1.setFont(new java.awt.Font("楷体_GB2312", 1, 24));
		jLabel1.setText("\u7ba1\u7406\u5458\u767b\u5f55");

		jLabel2.setText("\u7528\u6237\u540d\uff1a");

		jLabel3.setText("\u5bc6\u7801\uff1a");

		jButton1.setText("\u767b\u5f55");

		jButton1.addActionListener(new ActionListener() {

			@Override
			public void actionPerformed(ActionEvent e) {
				// TODO Auto-generated method stub
				String name = jTextField1.getText();
				String pwd = new String(jPasswordField1.getPassword());
				if (biz.login(name, pwd)) {
					LoginFrame.this.setVisible(true);
					LoginFrame.this.dispose();
					com.wdzl.frames.MainFrame mf = new com.wdzl.frames.MainFrame();
					mf.setResizable(true);
					mf.setLocationRelativeTo(null);
					mf.setTitle("职工管理系统主界面");
					mf.setVisible(true);
				} else {
					JOptionPane.showMessageDialog(null, "用户名/密码错误!", "错误消息", JOptionPane.ERROR_MESSAGE);
				}
			}

		});

		jButton2.setText("重置");
		jButton2.addActionListener(new ActionListener() {

			@Override
			public void actionPerformed(ActionEvent e) {
				// TODO Auto-generated method stub
				jTextField1.setText("");
				jPasswordField1.setText("");
			}

		});
		GroupLayout layout = new GroupLayout(
				getContentPane());
		getContentPane().setLayout(layout);
		layout
				.setHorizontalGroup(layout
						.createParallelGroup(
								GroupLayout.Alignment.LEADING)
						.addGroup(
								layout
										.createSequentialGroup()
										.addGroup(
												layout
														.createParallelGroup(
																GroupLayout.Alignment.LEADING)
														.addGroup(
																layout
																		.createSequentialGroup()
																		.addGap(
																				107,
																				107,
																				107)
																		.addComponent(
																				jLabel1))
														.addGroup(
																layout
																		.createSequentialGroup()
																		.addGap(
																				70,
																				70,
																				70)
																		.addComponent(
																				jButton1)
																		.addGap(
																				38,
																				38,
																				38)
																		.addComponent(
																				jButton2))
														.addGroup(
																layout
																		.createSequentialGroup()
																		.addGap(
																				50,
																				50,
																				50)
																		.addGroup(
																				layout
																						.createParallelGroup(
																								GroupLayout.Alignment.TRAILING)
																						.addComponent(
																								jLabel2)
																						.addComponent(
																								jLabel3))
																		.addPreferredGap(
																				LayoutStyle.ComponentPlacement.UNRELATED)
																		.addGroup(
																				layout
																						.createParallelGroup(
																								GroupLayout.Alignment.LEADING,
																								false)
																						.addComponent(
																								jTextField1)
																						.addComponent(
																								jPasswordField1,
																								GroupLayout.DEFAULT_SIZE,
																								139,
																								Short.MAX_VALUE)))
														.addGroup(
																layout
																		.createSequentialGroup()
																		.addGap(
																				26,
																				26,
																				26)
																		.addComponent(
																				jSeparator1,
																				GroupLayout.PREFERRED_SIZE,
																				274,
																				GroupLayout.PREFERRED_SIZE)))
										.addContainerGap(23, Short.MAX_VALUE)));
		layout
				.setVerticalGroup(layout
						.createParallelGroup(
								GroupLayout.Alignment.LEADING)
						.addGroup(
								layout
										.createSequentialGroup()
										.addContainerGap()
										.addComponent(jLabel1)
										.addPreferredGap(
												LayoutStyle.ComponentPlacement.RELATED)
										.addComponent(
												jSeparator1,
												GroupLayout.PREFERRED_SIZE,
												10,
												GroupLayout.PREFERRED_SIZE)
										.addPreferredGap(
												LayoutStyle.ComponentPlacement.UNRELATED)
										.addGroup(
												layout
														.createParallelGroup(
																GroupLayout.Alignment.BASELINE)
														.addComponent(jLabel2)
														.addComponent(
																jTextField1,
																GroupLayout.PREFERRED_SIZE,
																GroupLayout.DEFAULT_SIZE,
																GroupLayout.PREFERRED_SIZE))
										.addGap(18, 18, 18)
										.addGroup(
												layout
														.createParallelGroup(
																GroupLayout.Alignment.BASELINE)
														.addComponent(jLabel3)
														.addComponent(
																jPasswordField1,
																GroupLayout.PREFERRED_SIZE,
																GroupLayout.DEFAULT_SIZE,
																GroupLayout.PREFERRED_SIZE))
										.addGap(18, 18, 18)
										.addGroup(
												layout
														.createParallelGroup(
																GroupLayout.Alignment.BASELINE)
														.addComponent(jButton1)
														.addComponent(jButton2))
										.addContainerGap(17, Short.MAX_VALUE)));

		pack();
	}// </editor-fold>
	//GEN-END:initComponents

	/**
	 * @param args the command line arguments
	 */
	public static void main(String[] args) {
		java.awt.EventQueue.invokeLater(new Runnable() {
			public void run() {
				LoginFrame lf = new LoginFrame();
				lf.setTitle("管理员登录");
				lf.setLocationRelativeTo(null);
				lf.setResizable(false);
				lf.setVisible(true);
			}
		});
	}

	//GEN-BEGIN:variables
	// Variables declaration - do not modify
	private JButton jButton1;
	private JButton jButton2;
	private JLabel jLabel1;
	private JLabel jLabel2;
	private JLabel jLabel3;
	private JPasswordField jPasswordField1;
	private JSeparator jSeparator1;
	private JTextField jTextField1;
	// End of variables declaration//GEN-END:variables

}